<?php
/**
 * 修复线上品牌主页短链（长链接为gray的，例如：https://m.gray2.haohaozhu.cn/brand/home-page?uid=REwwaWx3TWlzdDJuTC9pL3BDNnFudz09OjdlNmQ1YTg2YzlmNmQ4YzI3M2ZkOWY2MTBiMDZiY2Uw）
 */
ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Doraemon\cache\ShortLink\ShortLinkCounter;
use Doraemon\model\ShortLink\ShortLink;

$res = ShortLink::selectByWhere(['reason' => '品牌号-品牌名称', 'long_link[~]' => 'gray']);
var_dump($res);
foreach ($res as $row) {
    $short_link = $row['short_link'];
    $longLink = $row['long_link'];
    $parseUrlArr = parse_url($longLink);
    var_dump($longLink);
    $longLink = 'https://' . 'm.haohaozhu.cn' . $parseUrlArr['path'] . '?' . $parseUrlArr['query'];
    var_dump($longLink);
    $longLinkApp = $row['long_link_app'];
    $link = [
        'h5' => $longLink,
        'app' => json_encode([
            "code" => 1,
            "data" => [
                "type" => "link",
                "link" => $longLinkApp
            ]
        ]),
    ];
    ShortLink::update(['long_link' => $longLink], ['id' => $row['id']]);
    $link_json = json_encode($link);
    ShortLinkCounter::set($link_json, $short_link);
}
die;
